home *** CD-ROM | disk | FTP | other *** search
/ MacHome 1999 Game / Image.bin / Role Playing and Strategy / Starbound II.hqx / Starbound II / AI agents / Gypsum.rsrc / ss$t_140 < prev    next >
Encoding:
Text File  |  1998-05-14  |  2.1 KB  |  73 lines

  1. situation orbital_squad
  2. vars
  3.    me : squad;
  4.    my_race : integer;
  5.    my_location : integer;
  6.    target : integer;
  7.    focus : squad;
  8.    loc : integer;
  9.    success : boolean;
  10.    p : planet;
  11.    c_struct : structure;
  12.    b_struct : structure;
  13.  
  14. begin
  15.    // Find the nearest enemy squad and move toward it
  16.    me := This_squad();
  17.    my_race := Squad_race(me);
  18.    my_location := Squad_hex(me);
  19.    target := -1;
  20.    focus := First_squad(-1);
  21.    while (focus <> nil) do
  22.       begin
  23.          if (Squad_race(focus) <> my_race) then
  24.             begin
  25.                loc := Squad_hex(focus);
  26.                if (target = -1) then
  27.                   begin
  28.                      target := loc;
  29.                   end;
  30.                else
  31.                   begin
  32.                      if (Planet_distance(my_location, loc) <
  33.                          Planet_distance(my_location, target)) then
  34.                         target := loc;
  35.                   end;
  36.             end;
  37.          focus := Next_squad(focus, -1);
  38.       end;
  39.    if (target = -1) then
  40.       begin
  41.          // if there is no squad, then move toward the nearest structure
  42.          p := This_planet();
  43.          b_struct := First_structure(p);
  44.          if (b_struct = nil) then            // If there are no structures then abort
  45.             begin
  46.                success := Move_squad(my_location);
  47.                exit;
  48.             end;
  49.          c_struct := Next_structure(p, b_struct);
  50.          while (c_struct <> nil) do
  51.             begin
  52.                if (Planet_distance(my_location, Structure_hex(p, c_struct)) <
  53.                    Planet_distance(my_location, Structure_hex(p, b_struct))) then
  54.                   b_struct := c_struct;
  55.                c_struct := Next_structure(p, c_struct);
  56.             end;
  57.          if (b_struct <> nil) then
  58.             begin
  59.                success := Move_squad(Structure_hex(p, b_struct));
  60.                if not success then
  61.                   success := Move_squad(my_location);
  62.             end;
  63.          else
  64.             success := Move_squad(my_location);
  65.       end;
  66.    else
  67.       begin
  68.          success := Move_squad(target);
  69.          if (not success) then
  70.             success := Move_squad(my_location);
  71.       end;
  72. end;
  73.